//定义个变量 字符串  基础数据类型
var a = "jiangxi"
let b = "jiujiang"

//定义变量 数值

var a1 = 1
let a2 = 2

//定义变量 布尔类型
var flag1 = true;
let flag2 = false;

// 定义空对象 引用类型
var obj1 = {}
let obj2 = {}

//定义空对象
var obj3 = new Object()
let obj4 = new Object()

//给空对象增加属性：属性名：属性值

var student ={
    username:"zhangsan",
    password:"123456",
    gender:"male",
    age:21,
    flag:true
}
console.log(student.username)
console.log(student.age);

//给student对象增加地址属性
student.address = "jiangxi jiujiang"

console.log(student.address);

//定义空对象并且给obj5赋值
let obj5 = new Object();
obj5.appName = "微信";
obj5.appPrice = 50;
obj5.appAuthor = "李四"
obj5.appstatus = true;
console.log(obj5.appPrice);


//定义一个普通函数
function addPerson(){

}

//定义普通函数  a b 形式参数 形参
function calc(a,b){
    console.log(a + b);
}
//运行函数  函数执行，函数调用  3,4 实参 实际参数
calc(3,4)
//定义普通函数  使用默认值
function printLog(a,b,c = 3){
    console.log(a+b+c);
}
//调用
printLog(1,2,4)

//定义普通函数，有返回值
function getNumber(){
    return 2;
}
console.log(getNumber());

//定义普通函数
function getValue(a,b){
    return a + b
}
console.log(getValue(1,2));

// 定义对象 username 属性名 age score
var personInfor = {
    username:"zhangsan",
    age:19,
    score:[80,85,88]
}

function getSum(o){
    let sum = 0
    for (let index = 0; index < o.score.length; index++ ){   
        sum = sum + o.score[index];
    }
    return sum;
}
console.log(getSum(personInfor));


//升级我的对象

var fruitObj = {
    fruitName:"赣南脐橙",
    fruitPrice:299,
    fruitColor:["red","blue","yellow"],
    price:function getPrice(){
        return this.fruitPrice //this指向当前对象
    },
    colorCount:function getColorCount(){
        return this.fruitColor.length;
    }
}
console.log(fruitObj.price());

// 普通函数
function getFruitInfo(){
    return 2 + 2
}
//匿名函数
let fruit1 = function(){
    return 2 + 2
}
fruit1()
//箭头函数
let fruit2 = ()=>{
    return 2 + 2;
}
fruit2()



let fruit3=(a)=>{ //a为形参
    console.log(a.username);
}
//fruit3(3)//3为实参
fruit3({username:"zhangsan"}) 


let fruit4=(b)=>{
    b()
}
fruit4(function (){
    console.log("this is fruit4")
})




